﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.IO;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace TradeSea
{
    public class TSContentManager
    {
        private Dictionary<string, Texture2D> Textures = new Dictionary<string, Texture2D>();

        private Texture2D Pixel;

        public Texture2D this[string name]
        {
            get { return this.Textures[name];  }
        }

        public SpriteFont ConsoleFont;

        private ContentManager Manager;

        public TSContentManager(ContentManager manager, MainGame game)
        {
            this.Manager = manager;

            this.LoadAll(manager.RootDirectory);

            ConsoleFont = this.Manager.Load<SpriteFont>("font_ConsoleFont");

            Pixel = new Texture2D(game.GraphicsDevice, 1, 1);
            Pixel.SetData<Color>(new Color[] { Color.White });
        }

        public void LoadAll(string path)
        {
            DirectoryInfo info = new DirectoryInfo(path);
            foreach (FileInfo item in info.GetFiles("*.xnb"))
            {
                if (item.Name.StartsWith("font_"))
                {
                    continue;
                }
                this.Load(item.Name);
            }
        }

        public void Load(string path)
        {
            //this.Textures[path] = this.Manager.Load<Texture2D>("path");
        }

        public void FillRectange(SpriteBatch batch, Rectangle rect, Color col)
        {
            batch.Draw(this.Pixel, rect, col);
        }
    }
}
